//
//  UIImage+Main.m
//  DayToDo
//
//  Created by karry on 2021/1/28.
//

#import "UIImage+Main.h"

@implementation UIImage (Main)

+ (NSString *)getImageNameWithPercent:(CGFloat)percent{
    
    NSString *imageName = @"emj_0";
    if (percent <= 0.2) {
        imageName = @"emj_0";
    }else if (percent > 0.2 && percent <= 0.4){
        imageName = @"emj_1";
    }else if (percent > 0.4 && percent <= 0.6){
        imageName = @"emj_2";
    }else if (percent > 0.6 && percent <= 0.8){
        imageName = @"emj_3";
    }else if (percent > 0.8){
        imageName = @"emj_4";
    }
    return imageName;
}

+ (UIImage *)getImageWithEmjString:(NSString *)emjString{
    
    return [UIImage getImageWithEmjString:emjString size:28];
    
}

+ (UIImage *)getImageWithEmjString:(NSString *)emjString size:(CGFloat)size{
    
    if (emjString == nil || emjString.length == 0) {
        return nil;
    }
    UILabel *label = [UILabel new];
    label.text = emjString;
    label.font = [UIFont systemFontOfSize:size];
    [label sizeToFit];
    UIImage *image = [label jk_screenshot];
    return image;
}

+ (UIImage *)imageNamedOrEmjName:(NSString *)name size:(CGFloat)size{
    
    UIImage *image = [UIImage imageNamed:name];
    if (image == nil) {
        image = [UIImage getImageWithEmjString:name size:size];
    }
    return image;
    
}

+ (UIImage *)imageNamedOrEmjName:(NSString *)name{
    
    return [UIImage imageNamedOrEmjName:name size:40];
    
    
}

+ (UIImage *)us_placeHolderImage{
    
    return [UIImage jk_imageWithColor:[UIColor.lightGrayColor colorWithAlphaComponent:.3]];
    
}

@end
